using BackData;
using Domain.DTOs.ProcessSteps;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Team.API.Applocation.Command.Makesteps;

namespace Team.API.Controllers
{
    /// <summary>
    /// 工艺工序（成品）管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MakestepsController : ControllerBase
    {
        private readonly IMediator mediator;

        public MakestepsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 分页查询成品工艺工序
        /// </summary>
        [HttpGet]
        public Task<APIPaging<MakestepListDTO>> GetProductMakestepList([FromQuery] GetMakestepListCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取成品工艺工序详情
        /// </summary>
        [HttpGet]
        public Task<APIResult<MakestepDetailDTO>> GetMakestepDetail([FromQuery] GetMakestepDetailCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 新增成品工艺工序
        /// </summary>
        [HttpPost]
        public Task<APIResult<MakestepListDTO>> CreateProductMakestep([FromBody] CreateMakestepCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 更新成品工艺工序
        /// </summary>
        [HttpPut]
        public Task<APIResult<MakestepListDTO>> UpdateProductMakestep([FromBody] UpdateMakestepCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 启用/禁用
        /// </summary>
        [HttpPut]
        public Task<APIResult<bool>> ToggleProductMakestep([FromBody] ToggleMakestepUseCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 删除（软删）工艺工序
        /// </summary>
        [HttpDelete]
        public Task<APIResult<bool>> DeleteProductMakestep([FromBody] DeleteMakestepCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取下拉选项
        /// </summary>
        [HttpGet]
        public Task<APIResult<MakestepSelectOptionsDTO>> GetProductSelectOptions()
        {
            return mediator.Send(new GetMakestepSelectionsCommand());
        }

        /// <summary>
        /// 获取工艺工序日志
        /// </summary>
        [HttpGet]
        public Task<APIResult<List<MakestepLogDTO>>> GetMakestepLogs([FromQuery] GetMakestepLogsCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取工艺流程树形结构
        /// 根据产品名称和版本查询工艺流程树形结构
        /// </summary>
        [HttpGet]
        public Task<APIResult<List<MakestepTreeDTO>>> GetMakestepTree([FromQuery] GetMakestepTreeCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 批量保存工艺流程
        /// 清除旧的工艺流程，保存新的工艺流程列表
        /// </summary>
        [HttpPost]
        public Task<APIResult<bool>> SaveMakestepList([FromBody] SaveMakestepListCommand request)
        {
            return mediator.Send(request);
        }
    }
}

